<template>
	<view>
		<view class="" v-if="value==0">
			<view class="c-box-nobg">
				<u-swiper :list="swiper" keyName="img"></u-swiper>
			</view>
			<view class="c-box-nobg">
				<u-search @search="search" v-model="keyword"></u-search>
			</view>
			<view class="c-box-nobg">
				<u-grid :col="3">
					<u-grid-item v-for="item in zw" :key="item.id" class="mt32" @click="changeList(item.id)">
						<text class="fs26 t-bl2">{{item.professionName}}</text>
					</u-grid-item>
				</u-grid>
			</view>
			<view class="c-box-nobg">
				<c-label title="招聘列表"></c-label>
			</view>
			<view class="c-box" v-for="item in zp" :key="item.id" @click="toDetail(item.id)">
				<view class="fl jsp">
					<view>{{item.name}}</view>
					<view class="fs26" style="color: red;">￥{{item.salary}}</view>
				</view>
				<view class="fl fs26">
					<u-icon name="map"></u-icon>
					<text>{{item.address}}</text>
				</view>
				<view class="fs26">
					{{item.obligation}}
				</view>
			</view>
		</view>
		<view class="" v-if="value==1">
			<view class="c-box-nobg">
				<c-label title="投递历史"></c-label>
			</view>
			<view class=" c-box" v-for="item in list" :key="item.id">
				<view class="fl jsp">
					<text>{{item.companyName}}</text>
					<text class="t-r">￥{{item.money}}</text>
				</view>
				<view class="mt8">
					{{item.postName}}
				</view>
				<view class="t-g1 mt8">
					{{item.satrTime}}
				</view>
			</view>
		</view>
		<view class="" v-if="value==2">
			<view class="c-box-nobg">
				<c-label title="基本信息"></c-label>
			</view>
			<view class="c-box-nobg">
				<view class="fl jsp mb16">
					<view>用户昵称</view>
					<view>{{user.nickName}}</view>
				</view>
				<u-line></u-line>
			</view>
			<view class="c-box-nobg">
				<view class="fl jsp mb16">
					<view>邮件</view>
					<view>{{user.email}}</view>
				</view>
				<u-line></u-line>
			</view>
			<view class="c-box-nobg">
				<view class="fl jsp mb16">
					<view>电话号码</view>
					<view>{{user.phonenumber}}</view>
				</view>
				<u-line></u-line>
			</view>
			<view class="c-box-nobg">
				<view class="fl jsp mb16">
					<view>性别</view>
					<u-icon :name="user.sex==0?'man':'woman'" :color="user.sex==0?'blue':'pink'"></u-icon>
				</view>
				<u-line></u-line>
			</view>
			<view class="c-box-nobg">
				<c-label title="求职信息"></c-label>
			</view>
			<u-collapse>
				<u-collapse-item title="工作经历">
					<u--textarea v-model="jl.experience" placeholder="请输入内容"></u--textarea>
				</u-collapse-item>
				<u-collapse-item title="最高学历">
					<u--textarea v-model="jl.mostEducation" placeholder="请输入内容"></u--textarea>
				</u-collapse-item>
				<u-collapse-item title="现居住地">
					<u--textarea v-model="jl.address" placeholder="请输入内容"></u--textarea>
				</u-collapse-item>
				<u-collapse-item title="期望职位">
					<view class="" @click="show=true">
						{{getposi(jl.positionId)}}
					</view>
					<u-action-sheet :actions="zwlist" 
					 :show="show" @close="show=false" :safeAreaInsetBottom="true" cancelText="取消" @select="zwchange"></u-action-sheet>
				</u-collapse-item>
				<u-collapse-item title="期望薪资">
					<u--textarea v-model="jl.money" placeholder="请输入内容"></u--textarea>
				</u-collapse-item>
				<u-collapse-item title="教育经历">
					<u--textarea v-model="jl.education" placeholder="请输入内容"></u--textarea>
				</u-collapse-item>
			</u-collapse>
			<view class="c-box-nobg">
				<u-button type="primary" @click="edit" text="编辑"></u-button>
			</view>
		</view>
		<u-tabbar :value="value" @change="name => value = name" :fixed="true" :placeholder="true"
			:safeAreaInsetBottom="true">
			<u-tabbar-item text="找工作" icon="home"></u-tabbar-item>
			<u-tabbar-item text="投递记录" icon="order"></u-tabbar-item>
			<u-tabbar-item text="个人简历" icon="account"></u-tabbar-item>
		</u-tabbar>
	</view>
</template>
用户、两部分。基本信息包括、、、性别，
求职信息包括工作经验、、、、、、个人简介。
<script setup>
	import {
		ref,
		getCurrentInstance
	} from "vue"
	import {
		onLoad
	} from '@dcloudio/uni-app'

	import {
		getSwiper
	} from "../../api";
	import {
		editJLAPI,
		getJLAPI,
		getListAPI,
		getZPAPI,
		getzwAPI
	} from "../../api/job";
	const {
		proxy
	} = getCurrentInstance()
	const value = ref(0)
	const swiper = ref([])
	const getlunbo = async () => {
		const res = await getSwiper()
		res.rows.map(item => {
			swiper.value.push({
				img: proxy.$http + item.advImg
			})
		})
	}
	const zw = ref([])
	const zwlist = ref([])
	const getzw = async () => {
		const res = await getzwAPI()
		res.rows.map(item=>{
			zwlist.value.push({
				value:item.id
			})
		})
		zwlist.value = zwlist.value.slice(0,10)
		zw.value = res.rows.slice(0, 9)
	}
	const zp = ref()
	const getzp = async (data) => {
		const res = await getZPAPI({
			professionId: data.id,
			name: data.name
		})
		zp.value = res.rows
	}
	const toDetail = (id) => {
		uni.navigateTo({
			url: "/subpages/job/detail/detail?id=" + id
		})
	}
	const changeList = (id) => {
		getzp({
			id: id,
			name: ''
		})
	}
	const keyword = ref('')
	const search = () => {
		getzp({
			id: '',
			name: keyword.value
		})
	}
	const list = ref()
	const getList = async () => {
		const res = await getListAPI()
		list.value = res.rows
	}
	const user = ref(uni.getStorageSync('user'))
	const jl = ref()
	const getJl = async () => {
		const res = await getJLAPI(user.value.userId)
		jl.value = res.data
		console.log(res);
	}
	const show = ref(false)
	const getposi =(id)=>{
		return id?zw.value.filter(item=>item.id==id)[0].professionName:''
	}
	const zwchange =(item)=>{
		jl.value.positionId = item.value
	}
	const edit =async()=>{
		const res = await editJLAPI(jl.value)
		if(res.code==200){
			uni.showToast({
				title:'编辑成功'
			})
			getJl()
		}
	}
	onLoad(() => {
		getlunbo()
		getzw()
		getList()
		getzp({})
		getJl()

	})
</script>

<style>

</style>